<template>
  <div class="nav-header">
    <el-icon class="fold-menu" v-show="!isopen" @click="changeOpen">
      <Fold />
    </el-icon>
    <el-icon class="fold-menu" v-show="isopen" @click="changeOpen">
      <Expand />
    </el-icon>
    <div class="content">
      <div><sy-breadcrumb :breadcrumbs="breadcrumbs"></sy-breadcrumb></div>
      <user-info />
    </div>
  </div>
</template>

<script lang="ts">
import { computed, defineComponent, ref } from 'vue'
import UserInfo from './user-info.vue'
import SyBreadcrumb from '@/base-ui/breadcrumb'
import { pathMapBreadcrumbs } from '@/utils/map-menus'
import { useStore } from '@/store'
import { useRoute } from 'vue-router'

export default defineComponent({
  emits: ['changeOpen'],
  components: {
    UserInfo,
    SyBreadcrumb
  },
  setup(props, { emit }) {
    let isopen = ref(false)
    const changeOpen = () => {
      isopen.value = !isopen.value
      emit('changeOpen', isopen.value)
    }

    // 面包屑的数据: [{name: , path: }]
    const store = useStore()
    const breadcrumbs = computed(() => {
      const userMenus = store.state.login.userMenus
      const route = useRoute()
      const currentPath = route.path
      return pathMapBreadcrumbs(userMenus, currentPath)
    })
    return { isopen, breadcrumbs, changeOpen }
  }
})
</script>
<style scoped lang="less">
.nav-header {
  display: flex;
  width: 100%;

  .fold-menu {
    font-size: 30px;
    cursor: pointer;
  }
  .content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex: 1;
    padding: 0 20px;
  }
}
</style>
